package arithmetic1.test;

import java.util.Scanner;

/*
    凯撒加密
 */
public class CaesarCipher {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入明文:");
        String string=scanner.next();
        System.out.println("加密后为:");
        System.out.println(caesarCipher(string));
    }

    //凯撒加密,将字母全部后移3位形成密文
    public static String caesarCipher(String str){
        String string="";
        for (int i=0;i<str.length();i++){
            char c=str.charAt(i);
            if((c>'w' && c<'z') || c>'W' && c<'Z'){
                string+=(char)(c-23);
            }else {
                string+=(char)(c+3);
            }
        }
        return string;
    }
}
